package com.zeros.latte.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.ContentFrameLayout;

import com.zeros.latte.R;
import com.zeros.latte.delegates.LatteDelegate;

import me.yokeyword.fragmentation.SupportActivity;

/**
 * 此Activity仅仅是一个容器 on 2018/1/27.
 */

public abstract class ProxyActivity extends SupportActivity {

    //    抽象方法-用于返回我们的fragment
    public abstract LatteDelegate setRootDelegate();

    //    创造容器
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initContainer(savedInstanceState);
    }

    //    设置容器-利用ContentFrameLayout
    private void initContainer(@Nullable Bundle savedInstanceState) {
        ContentFrameLayout container = new ContentFrameLayout(this);
        container.setId(R.id.delegate_container);
        setContentView(container);

        if (savedInstanceState == null) {
//            fragment库独有方法,把 根delegate(fragment)传入进来
            loadRootFragment(R.id.delegate_container, setRootDelegate());
        }
    }


//    性能优化--此处是单activity架构所以退出就销毁
    @Override
    protected void onDestroy() {
        super.onDestroy();
//        以下两个方法不一定执行
        System.gc();
        System.runFinalization();
    }
}
